<template>
	<view class="content">
		<view class="form">
			<view class="inputWrapper">
				<input type="text" v-model="email" placeholder="请输入您的邮箱" />
			</view>
			<view class="inputWrapper">
				<input type="text" v-model="nickName" placeholder="请输入您的昵称" />
			</view>
			<view class="inputWrapper">
				<input type="password" v-model="password" placeholder="请确认您的密码" />
			</view>
			<view class="inputWrapper">
				<input type="number" v-model="phoneNum" placeholder="请确认您的电话号码" />
			</view>
			<view class="loginBtn" @tap="toRegister">
				<text>注册</text>
			</view>
			<view class="register" @tap="toLogin">
				<text>已有账号，立即登录</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				email: '555@qq.com',
				nickName: 'test6',
				password: '666666',
				phoneNum: '66666666666'
			}
		},
		methods: {
			toRegister() {


				if (this.email.length == 0 ||
					this.nickName.length == 0 ||
					this.phoneNum.length == 0 ||
					this.password.length == 0) {

					uni.showToast({
						title: '请输入完整信息！',
						icon: 'none'
					})

				} else if (this.phoneNum.length != 11) {

					uni.showToast({
						title: '请输入正确手机号！',
						icon: 'none'
					})

				} else if (this.password.length != 6) {

					uni.showToast({
						title: '请设置6位数密码！',
						icon: 'none'
					})

				} else {

					console.log("test");

					this.$post(this.$api.USER_REGISTER, {
						
								id: "0",
								email: this.email,
								mpassword: this.password,
								mname: this.nickName,
								phone: this.phoneNum,
								
						}).then(res => {
						console.log(res)

						if (res.code == 200) {
							
							uni.showToast({
								title: '注册成功！',
								duration: 1000
							});
							setTimeout(function() {
								uni.navigateTo({
									url: '../login/login'
								})
							}, 1000);
							
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					})


				}




			},


			toLogin() {
				uni.navigateBack({
					delta: 1
				})
			}


		}
	}
</script>

<style scoped lang="scss">
	.content {
		background: #33a69e;
		width: 100vw;
		height: 100vh;

		.form {
			padding: 100upx;

			.inputWrapper {
				width: 100%;
				height: 80upx;
				background: white;
				border-radius: 20px;
				box-sizing: border-box;
				padding: 0 20px;
				margin-top: 25px;

				input {
					width: 100%;
					height: 100%;
					text-align: center;
					font-size: 15px;
				}
			}

			.loginBtn {
				width: 100%;
				height: 80upx;
				background: #77B3D7;
				border-radius: 50upx;
				margin-top: 50px;
				display: flex;
				justify-content: center;
				align-items: center;

				text {
					color: white;
				}
			}

			.register {
				text-align: center;
				color: #EAF6F9;
				font-size: 15px;
				margin-top: 20px;
			}
		}
	}
</style>
